package com.gf.framework.common.utils.hashhash;

import lombok.Data;

import java.util.*;

/**
 * @author gaofei
 * @date 2022/6/12 17:25
 */
@Data
public class HashHashItr<K1, K2, V> implements Iterator<HashHashEntry<K1, K2, V>> {
    private int index = 0;
    private final List<HashHashEntry<K1, K2, V>> hashHashEntries;

    public HashHashItr(int size, Set<Map.Entry<K1, Map<K2, V>>> setMap) {
        hashHashEntries = new ArrayList<>(size);
        setMap.forEach(k1MapEntry -> k1MapEntry.getValue().forEach((k2, v) -> hashHashEntries.add(new HashHashEntry<>(k1MapEntry.getKey(), k2, v))));
    }

    @Override
    public boolean hasNext() {
        return index < hashHashEntries.size();
    }

    @Override
    public HashHashEntry<K1, K2, V> next() {
        return hashHashEntries.get(index++);
    }
}
